/*
 * @Date: 2023-03-09 21:37:34
 * @LastEditors: Zireael 1193875164@qq.com
 * @LastEditTime: 2023-03-10 20:31:02
 * @FilePath: \A19\backend\src\api\Create\ApiCreateUserHomework.ts
 */
import { ApiCall } from "tsrpc";
import { ReqCreateUserHomework, ResCreateUserHomework } from "../../shared/protocols/Create/PtlCreateUserHomework";
import { Global } from '../../Global/index';

export default async function (call: ApiCall<ReqCreateUserHomework, ResCreateUserHomework>) {
    // TODO
    const user = call.currentUser
    const { test,examOrHomework,submitTime,answers,status,score } = call.req

    await Global.collection(examOrHomework === 'exam'?'userTests':'userHomework').insertOne({
        student:user._id,
        test,
        submitTime,
        answers,
        score
    })

    call.succ({})
}